//
// Created by GYC on 2021/6/3.
//
#include "../../common.h"


class Solution {
public:
    bool checkSubarraySum(vector<int>& nums, int k) {

        if (nums.size() < 2) {
            return false;
        }

        unordered_map<int, int> note{};
        note[0] = -1;

        int last = 0;
        for(int i = 0; i < nums.size(); ++i) {
            last = (last + nums[i]) % k;
            if (note.count(last)) {
                if (i - note[last] >= 2) {
                    return true;
                }
            }else {
                note[last] = i;
            }
        }
        return false;
    }
};